package com.qding.park.adapter.test.adapter.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.alibaba.fastjson.JSONObject;
import com.qding.park.common.core.exceptions.business.adapter.AdapterException;
import com.qding.park.common.core.exceptions.system.NetWorkException;
import com.qding.park.manager.pojo.ap.ApPark;
import com.qding.park.target.common.AdapterParam;
import com.qding.park.target.common.adapter.ParkAdapter;
import com.qding.park.target.common.entity.AdParkConnStatu;
import com.qding.park.target.common.entity.AdParkInfo;
import com.qding.park.target.common.entity.AdcarInParkTag;
import com.qding.park.target.common.enums.ParkConnStatuEnum;

//@Component("bsg.parkAdapter")
/**
 * @ClassName ParkAdapterImpl
 * @Description TODO(车场实现)
 * @author Administrator
 * @Date 2016年8月28日 下午9:46:53
 * @version 1.0.0
 */
public class ParkAdapterImpl implements ParkAdapter{
	
	private static final Log _log = LogFactory.getLog(ParkAdapterImpl.class);
	
	public ParkAdapterImpl(String url){
//		this.setAdapterUrl(url);
	}
	
	/* (非 Javadoc)
	 * Description:
	 * @see com.qding.park.target.common.adapter.ParkAdapter#getTempStopNum(java.lang.String)
	 * 根据车场id 返回临停车位数
	 */
	@Override
	public AdParkInfo getTempStopNum(String parkId,String userId) throws NetWorkException, AdapterException {
		String url ="";
		JSONObject jsonObj = new JSONObject();
		jsonObj.put("clientID", parkId);
		Map<String, String> params = new HashMap<String, String>();
		params.put("UserID", "110");
//		params.put("RequestFun", ConstantFunction.Parking_GetParkingArea);
		params.put("RequestData", jsonObj.toJSONString());
		params.put("Sign", "ddd");
		try {
//			_log.info("adapter request:"+params);
//			String result = HttpUtil.doPost(this.getAdapterUrl(), params);
//			_log.info("adapter response:"+result);
//			java.io.Reader in = new StringReader(result);
//			Document doc = (new SAXBuilder()).build(in);
//
//			String temp = doc.getRootElement().getValue();
//			in.close();
//			ResponseMsg repmsg = JSONObject.parseObject(temp, ResponseMsg.class);
//			String errorCode=repmsg.getErrorCode();
//			if(!ErrorCodeEnum.SUCCESS.getCode().equals(errorCode)){
//				throw new AdapterException(AdapterException.TypeEnum.EXCEPTION_ADAPTER_FAIL.getId(),null,
//						ExceptionMessage.createExceptionMessage(AdapterException.TypeEnum.EXCEPTION_ADAPTER_FAIL.getDesc(),
//								repmsg.getErrorMsg(), ConstantFunction.Parking_GetParkingArea+" adpater处理出错 :"+repmsg.getErrorMsg()));
//			}
//			//{"result":{"areaName":"八卦岭四区停车场","areaTotal":"50","areaRemain":"49"}
//			JSONObject data = (JSONObject)repmsg.getResult();
//			int areaRemain=Integer.valueOf(data.getString("areaRemain"));
//			return areaRemain;
		    AdParkInfo  parkInfo=new AdParkInfo();
		    parkInfo.setRestSpace(48);
			return parkInfo;
			
		} 
		catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

//	/* (非 Javadoc)
//	 * Description:
//	 * @see com.qding.park.target.common.adapter.ParkAdapter#queryParkingByCarnum(java.lang.String)
//	 * 查询车辆所停车场
//	 */
//	@Override
//	public ApPark queryParkingByCarnum(String carNum) {
//		ApPark park=new ApPark();
//		
//		park.setParkId("00001");
//		park.setParkName("君莲新城中城苑");
//		return park;
//	}

//	@Override
//	public List<ApPark> queryParkConnStatus(String params) throws NetWorkException, AdapterException {
//		// TODO Auto-generated method stub
//		return null;
//	}

    @Override
    public AdcarInParkTag carInParkTag(String carNum, String parkCode,String userId) {
        AdcarInParkTag  inParkTag=new AdcarInParkTag();
        inParkTag.setInOutFlag(false);
        return inParkTag;
    }

    @Override
    public AdParkConnStatu getParkConnStatu(String parkCode,String userId) {
        AdParkConnStatu  connStatu=new AdParkConnStatu();
        connStatu.setConnStatu(ParkConnStatuEnum.ON_LINE);
        connStatu.setLastRequestTime(new Date());
        connStatu.setMsg("车场消息");
        return connStatu;
    }
	
	
}
